home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / AutoBin Source / AutoBin.c < prev    next >
Text File  |  1993-12-09  |  6KB  |  277 lines

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **  MXM         Matthew Xavier Mora
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **  12/08/93            MXM        Made this program called Auto bin to bin hex a file
  25. **    12/09/91            LDR        Added support for new "Select File…" menu item
  26. **                                Quit now sends AEVT to self to be politically correct
  27. **                                Added support for the new gSplashScreen
  28. **    11/24/91            LDR        Added support for the Apple Menu (duh!)
  29. **    10/29/91            SCS        Changes for THINK C 5
  30. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  31. **                                Added a bunch of comments for clarification
  32. **    10/06/91    00:02    MTC        Converted to MPW C
  33. **    04/09/91    00:02    LDR        Added to Projector
  34. **
  35. ******************************************************************************/
  36.  
  37.  
  38. #include "DSGlobals.h"
  39. #include "DSUserProcs.h"
  40. #include "DSAppleEvents.h"
  41.  
  42. #include "AutoBin.h"
  43. #include "binhex.h"
  44.  
  45. #ifndef THINK_C
  46.     #include <Fonts.h>
  47.     #include <OSEvents.h>
  48.     #include <Resources.h>
  49.     #include <Desk.h>
  50. #endif
  51.  
  52.  
  53. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  54. EventRecord    gEvent;
  55. MenuHandle    gAppleMenu, gFileMenu;
  56. WindowPtr    gSplashScreen;
  57. short         gRefNum;
  58. Byte NewLine[4];    
  59.  
  60.  
  61. extern void _DataInit();    
  62.  
  63. /*
  64.     Simple routine installed by InitDialogs for the Resume button in Bomb boxes
  65. */
  66. #pragma segment Main
  67.  
  68. void Panic () {
  69.     ExitToShell ();
  70. }
  71.  
  72.  
  73. #pragma segment Initialize
  74. void InitToolbox (void) 
  75. {
  76.  
  77. #ifndef THINK_C
  78.     UnloadSeg ((Ptr) _DataInit );
  79. #endif
  80.  
  81.     InitGraf ( &qd.thePort );
  82.     InitFonts ();
  83.     InitWindows ();
  84.     InitMenus ();
  85.     TEInit ();
  86.     InitDialogs ((ResumeProcPtr) Panic );
  87.     InitCursor ();
  88.     FlushEvents ( everyEvent, 0 );
  89.     
  90.     // how about some memory fun! Two should be enough!
  91.     MoreMasters ();
  92.     MoreMasters ();
  93.     }
  94.  
  95. /*
  96.     Let's setup those global variables that the DropShell uses.
  97.     
  98.     If you add any globals for your own use,
  99.     init them in the InitUserGlobals routine in DSUserProcs.c
  100. */
  101. #pragma segment Initialize
  102. Boolean InitGlobals (void) 
  103. {
  104.     long aLong;
  105.  
  106.     gDone            = false;
  107.     gOApped            = false;    // probably not since users are supposed to DROP things!
  108.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  109.     gSplashScreen    = NULL;
  110.     gRefNum         = 0;
  111.     return(InitUserGlobals());    // call the user proc
  112. }
  113.  
  114. /*
  115.     Again, nothing fancy.  Just setting up the menus.
  116.     
  117.     If you add any menus to your DropBox - insert them here!
  118. */
  119. #pragma segment Initialize
  120. void SetUpMenus (void) {
  121.  
  122.     gAppleMenu = GetMenu ( kAppleNum );
  123.     AddResMenu ( gAppleMenu, 'DRVR' );
  124.     InsertMenu ( gAppleMenu, 0 );
  125.  
  126.     gFileMenu = GetMenu ( kFileNum );
  127.     InsertMenu ( gFileMenu, 0 );
  128.     DrawMenuBar ();
  129. }
  130.  
  131. /*
  132.     This routine is called during startup to display a splash screen.
  133.     
  134.     This was recommend by the Blue Team HI person, John Sullivan, who
  135.     feels that all apps should display something so that users can easily
  136.     tell what is running, and be able to switch by clicking.  Thanks John!
  137. */
  138. #pragma segment Initialize
  139. void InstallSplashScreen(void) 
  140. {
  141.     #define windowPicID    128
  142.  
  143.     PicHandle    picH;
  144.  
  145.     if (!gSplashScreen) {  // show the splash screen window
  146.         picH = GetPicture(windowPicID);
  147.         if (picH) {
  148.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  149.             if (gSplashScreen) {
  150.                 //SetWindowPic(gSplashScreen, picH);
  151.                 // Don't show it here, since we only want to it for oapp launches!
  152.                  ShowWindow(gSplashScreen);
  153.                  SetPort(gSplashScreen);
  154.                  MoveTo(10,20);
  155.                  DrawString("\pReady to encode a file.");
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161.  
  162. /*    --------------- Standard Event Handling routines ---------------------- */
  163. #pragma segment Main
  164. void ShowAbout () {
  165.     (void) Alert ( 128, NULL );
  166.     }
  167.  
  168.  
  169. #pragma segment Main
  170. void DoMenu ( long retVal ) {
  171.     short    menuID, itemID;
  172.     Str255    itemStr;
  173.  
  174.     menuID = HiWord ( retVal );
  175.     itemID = LoWord ( retVal );
  176.     
  177.     switch ( menuID ) {
  178.         case kAppleNum:
  179.             if ( itemID == 1 )
  180.                 ShowAbout ();    /*    Show the about box */
  181.             else
  182.             {
  183.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  184.                 OpenDeskAcc(itemStr);
  185.             }
  186.             break;
  187.             
  188.         case kFileNum:
  189.             if ( itemID == 1 )
  190.                 SelectFile();        // call file selection userProc
  191.             else
  192.                 SendQuitToSelf();    // send self a 'quit' event
  193.             break;
  194.         
  195.         default:
  196.             break;
  197.             
  198.         }
  199.     HiliteMenu(0);        // turn it off!
  200.     }
  201.  
  202.  
  203. #pragma segment Main
  204. void DoMouseDown ( EventRecord *curEvent ) {
  205.     WindowPtr    whichWindow;
  206.     short        whichPart;
  207.  
  208.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  209.     switch ( whichPart ) {
  210.         case inMenuBar:
  211.             DoMenu ( MenuSelect ( curEvent->where ));
  212.             break;
  213.         
  214.         case inSysWindow:
  215.             SystemClick ( curEvent, whichWindow );
  216.             break;
  217.         
  218.         case inDrag:
  219.             #ifndef THINK_C
  220.                 DragWindow ( whichWindow, curEvent->where, &qd.screenBits.bounds );
  221.             #else
  222.                 DragWindow ( whichWindow, curEvent->where, &screenBits.bounds );
  223.             #endif
  224.         default:
  225.             break;
  226.         }
  227.     }
  228.  
  229.  
  230. #pragma segment Main
  231. void DoKeyDown ( EventRecord *curEvent ) {
  232.     if ( curEvent->modifiers & cmdKey )
  233.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  234.     }
  235.  
  236.  
  237.  
  238. #pragma segment Main
  239. void main ( ) 
  240. {
  241.  
  242.     InitToolbox ();
  243.     if ( InitGlobals () ) {    // if we succeeding in initting self
  244.         if ( !gHasAppleEvents )
  245.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  246.         else {
  247.             InitAEVTStuff ();
  248.             SetUpMenus ();
  249.             InstallSplashScreen ();
  250.             
  251.             while ( !gDone ) {
  252.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  253.                 if ( gWasEvent ) {
  254.                     switch ( gEvent.what ) {
  255.                         case kHighLevelEvent:
  256.                             DoHighLevelEvent ( &gEvent );
  257.                             break;
  258.                             
  259.                         case mouseDown:
  260.                             DoMouseDown ( &gEvent );
  261.                             break;
  262.                             
  263.                         case keyDown:
  264.                         case autoKey:
  265.                             DoKeyDown ( &gEvent );
  266.                             break;
  267.                             
  268.                         default:
  269.                             break;
  270.                     }
  271.                 }
  272.             }
  273.         }
  274.         DisposeUserGlobals();    // call the userproc to clean itself up
  275.     }
  276. }
  277.